package com.xiangxiao.rpan.authority.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @Projectname: HttpServletRequestUtil
 * @Author: xiangxiao
 * @Email: 573768011@qq.com
 * @Data:2023/7/11 23:55
 */
public class HttpServletRequestUtil {
  /**
   * 获取请求
   *
   * @return
   */
  public static HttpServletRequest getRequest() {
    return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  }

  /**
   * 判断是否是app客户端
   *
   * @return
   */
  public static boolean isAppClient() {
    HttpServletRequest request = getRequest();
    String client = request.getHeader("client");
    if (StringUtils.isBlank(client) || !"app".equals(client.toLowerCase())) {
      return false;
    }
    return true;
  }

  /**
   * 获取token
   * @return
   */
  public static String getToken() {
    HttpServletRequest request = getRequest();
    return request.getHeader("token");
  }
}
